package code.refactoring.View;
import code.refactoring.Model.Board;

public class FieldDrawer implements IDrawer {

	private Board gameBoard;

	public void setGameBoard(Board gameBoard) {
		if (gameBoard != null) {
			this.gameBoard = gameBoard;
		}
	}

	/**
	 * draws the game table 
	 */
	@Override
	public void draw() {
		int rows = gameBoard.getRows();
		int columns = gameBoard.getColumns();
		int rowCount = 1;
		int columnCount = 1;
		// Setting number of columns
		System.out.println();
		System.out.print("# ");
		for (int col = 0; col < columns; col++) {
			if (col % 2 == 0) {
				System.out.print(columnCount + " ");
				columnCount++;
			}
		}
		System.out.println();
		for (int row = 0; row < rows; row++) {
			// setting numbers of rows
			if (row % 2 == 0) {
				System.out.print(rowCount + " ");
				rowCount++;
			}
			for (int col = 0; col < columns; col++) {
				Object data = gameBoard.getDataForCell(row, col);
				// when it's the first column before the dash must be added 2
				// whitespaces
				if (row % 2 != 0 && col == 0) {
					System.out.print("  " + data);
				} else {
					System.out.print(data);
				}
			}
			System.out.println();

		}
		System.out.println();

	}
}
